home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- From: jgustafs@sisna.com (Josh Gustafson)
- Subject: A question on generic classes
- Organization: Source Internet Services
- X-Newsreader: News Xpress 2.0 Beta #0
- Date: Tue, 19 Mar 96 03:55:12 GMT
- NNTP-Posting-Host: dialup1147.sisna.com
- Message-ID: <314e1c88.0@news.sisna.com>
- Path: news.sisna.com!DIALUP1147
-
- Hi all!
-
- I'm giving myself a crash course in C++, and I have a question regarding
- generic classes.
-
- Say I've got some silly little template:
-
- template <class the_type> class blah {
- the_type data;
- public:
- blah( the_type param ) { data = param };
- }
-
- Ok, now if I want to declare an object that uses, say, ints, i do:
-
- blah<int> my_var( some_int_value );
- blah<int> my_other_var = blah( some_int_value );
-
- Now, say I want to declare a specialized version of this template that always
- uses ints as the_type. Could I do this with a typedef?
-
- typedef blah<int> intblah;
- intblah my_var( some_int_value );
- intblah my_other_var = intblah( some_int_value );
-
- And, if so, what will most compilers (Watcom C++ 10.5, in particular) about
- optimizing this? That is, will the template simply be expanded in place of
- each reference to intblah, or would it create a new class with ints plugged in
- place of the_type?
-
- If the above does not work, what is the best way to do what I'm trying to do?
-
- If this question hasn't made any sense, let me know and I'll see if i can't
- clear it up a bit...
-
-
-
- --
- Josh Gustafson (jgustafs@sisna.com)
-